//引入样式
require("../../assets/css/reset.css")
require('../../assets/css/normalize.css')
require('../../assets/fonts/iconfont.css')
require('../../assets/css/tabbar.less')
require('./mine.less');


//引入模块
const dom = require('../../utils/dom.js');
const axios = require('axios');
document.addEventListener("DOMContentLoaded", function () {
    dom.tabbar("mine");
    // 获取token
    let token = localStorage.getItem("token");
    axios.defaults.headers.common['Authorization'] = "Bearer " + token;
    axios.defaults.baseURL = 'http://fitness.h5.itsource.cn:3701'; //设置AJAX基础路径
    axios.get('/api/user/info').then(res => {
        // 渲染用户名
        dom.get('#nickname').textContent = res.data.data.nickName;
        //渲染运动时长
        dom.get('#duration').textContent = res.data.data.duration;
        // 渲染消耗卡路里
        dom.get('#calorie').textContent = res.data.data.calorie;

        // 退出登录功能
        const btn = dom.get("#exitBtn");
        btn.addEventListener("click", function () {
            localStorage.removeItem("token");
            location.href = 'login.html'
        })
    })
})